import request from '@/request/request'

// 获取转账单列表
export function getTransferList(params) {
  return request({
    url: '/finance/accountFlow/list',
    method: 'get',
    params: {
      ...params,
      billType: 'transfer' // 指定为转账类型
    }
  })
}

// 添加转账单
export function addTransfer(data) {
  return request({
    url: '/finance/accountFlow/add',
    method: 'post',
    data: {
      ...data,
      billType: 'transfer'
    }
  })
}

// 更新转账单
export function updateTransfer(data) {
  return request({
    url: '/finance/accountFlow/update',
    method: 'put',
    data: {
      ...data,
      billType: 'transfer'
    }
  })
}

// 删除转账单
export function deleteTransfer(id) {
  return request({
    url: `/finance/accountFlow/delete/${id}`,
    method: 'delete'
  })
}

// 获取转账单详情
export function getTransferDetail(id) {
  return request({
    url: `/finance/accountFlow/list`,
    method: 'get',
    params: {
      billType: 'transfer',
      billId: id,
      pageSize: 1
    }
  })
}

// 批量删除转账单
export function batchDeleteTransfer(ids) {
  return Promise.all(ids.map(id => deleteTransfer(id)))
}

// 审核转账单
export function approveTransfer(id) {
  return request({
    url: '/finance/accountFlow/update',
    method: 'put',
    data: {
      id,
      billType: 'transfer',
      status: 1 // 已审核
    }
  })
}

// 批量审核转账单
export function batchApproveTransfer(ids) {
  return Promise.all(ids.map(id => approveTransfer(id)))
}

// 导出转账单
export function exportTransfer(params) {
  return Promise.resolve({ data: null }) // 暂不实现导出
}

// 获取转账单统计
export function getTransferStats() {
  return request({
    url: '/finance/accountFlow/list',
    method: 'get',
    params: {
      billType: 'transfer',
      pageSize: 1000
    }
  })
}